{template 'common/header'}
<script>
    document.onkeydown=function(e){
        var a=e||window.event;//加这个火狐下不会报 event is  undefind
        if (a.keyCode == 13){
            var region_id = $("#region_id").val();
            var key_word = $("#key_word").val();
            var day = $("#day").val();
            var status = $("#status").val();
            var goods_status = $("#goods_status").val();
            var goods_express = $("#goods_express").val();
            var from_member = $("#from_member").val();
            var cashier = $("#cashier").val();
            var goods_remark = $("#goods_remark").val();
            location.href="{php echo $this->createWebUrl('orders',array('op' => 'index'))}&region_id="+region_id+"&key_word="+key_word+"&day="+day+"&status="+status+"&goods_status="+goods_status+"&goods_express="+goods_express+"&from_member="+from_member+"&cashier="+cashier+"&goods_remark="+goods_remark;
        }
    }
    function printdiv(printpage)
    {
        var newstr = printpage.innerHTML;
        var oldstr = document.body.innerHTML;
        document.body.innerHTML =newstr;
        window.print();
        document.body.innerHTML=oldstr;
        location.reload();
//        return false;
    }
    function find(){
        $(".find").click();
    }
    $(function(){
        $("#page-size").on("change",function(){
            find();
        });
        $(".find").click(function(){
            var key_word = $("#key_word").val();
            var day = $("#day").val();
            var end_day = $("#end_day").val();
            var status = $("#status").val();
            var goods_status = $("#goods_status").val();
            var goods_express = $("#goods_express").val();
            var company_id = $("#company_id").val();
            var server_id = $("#server_id").val();
            var goods_remark = $("#goods_remark").val();
            var order_remark = $("#order_remark").val();
            var page_size = $("#page-size").val();
            location.href="{php echo $this->createWebUrl('express',array('op' => 'order_list'))}&key_word="+key_word+"&day="+day+"&end_day="+end_day+"&status="+status+"&goods_status="+goods_status+"&goods_express="+goods_express+"&goods_remark="+goods_remark+"&order_remark="+order_remark+"&page_size="+page_size+"&company_id="+company_id+"&server_id="+server_id;
        });
        $(".finish-all").click(function(){
            var region_id = $("#region_id").val();
            var key_word = $("#key_word").val();
            var day = $("#day").val();
            var status = $("#status").val();
            location.href = "{php echo $this->createWebUrl('orders',array('op' => 'finish_all'))}&region_id="+region_id+"&key_word="+key_word+"&day="+day+"&status="+status;
        });
        $(".export-data").click(function(){
            var key_word = $("#key_word").val();
            var day = $("#day").val();
            var end_day = $("#end_day").val();
            var status = $("#status").val();
            var goods_status = $("#goods_status").val();
            var goods_express = $("#goods_express").val();
            var company_id = $("#company_id").val();
            var server_id = $("#server_id").val();
            var goods_remark = $("#goods_remark").val();
            var order_remark = $("#order_remark").val();
//            var page_size = $("#page-size").val();
            location.href="{php echo $this->createWebUrl('express',array('op' => 'export'))}&key_word="+key_word+"&day="+day+"&end_day="+end_day+"&status="+status+"&goods_status="+goods_status+"&goods_express="+goods_express+"&goods_remark="+goods_remark+"&order_remark="+order_remark+"&company_id="+company_id+"&server_id="+server_id;
        });
        $("#selectAll").click(function () {
            var isChecked = $(this).is(":checked");
            if(isChecked) {
                $("input:checkbox").each(function () {
                    $(this).prop('checked', true);
                });
            }else{
                $("input:checkbox").each(function () {
                    $(this).prop('checked', false);
                });
            }
        });
        $(".del-order").click(function(){
            if(confirm("是否确定删除订单？")){
                var order_id = $(this).attr("order_id");
                if(order_id > 0){
                    var url = "{php echo $this->createWebUrl('express',array('op' => 'del'))}";
                    $.ajax({
                        type : "post",
                        url : url,
                        data : {'order_id' : order_id},
                        success : function(data){
                            var json = JSON.parse(data);
                            if(data == 111){
                                location.reload();
                            }else{
                                alert(json.message);
                            }
                        }
                    });
                }
            }
        });
        $(".finish-day-orders").click(function(){
            var day = $("#finish-day").val();
            if(confirm("是否确定完成"+day+"的订单？")){
                var url = "{php echo $this->createWebUrl('orders',array('op' => 'finish_day_orders'))}";
                $.ajax({
                    type : "post",
                    url : url,
                    data : {"day" : day},
                    success : function(data){
                        if(data == 111){
                            alert("操作成功！");
                            location.reload();
                        }
                    }
                });
            }
        });
        $(".print").on('click',function(){
            var key_word = $("#key_word").val();
            var day = $("#day").val();
            var end_day = $("#end_day").val();
            var status = $("#status").val();
            var goods_status = $("#goods_status").val();
            var goods_express = $("#goods_express").val();
            var company_id = $("#company_id").val();
            var server_id = $("#server_id").val();
            var goods_remark = $("#goods_remark").val();
            var order_remark = $("#order_remark").val();
            var page_size = $("#page-size").val();
            var url="{php echo $this->createWebUrl('express',array('op' => 'print'))}&key_word="+key_word+"&day="+day+"&end_day="+end_day+"&status="+status+"&goods_status="+goods_status+"&goods_express="+goods_express+"&goods_remark="+goods_remark+"&order_remark="+order_remark+"&page_size="+page_size+"&company_id="+company_id+"&server_id="+server_id;
            $.ajax({
                type : 'post',
                url : url,
                success : function(data){
                    $("#div_print").html(data);
                    $("#div_print").show();
                    var div_print=document.getElementById("div_print");
                    printdiv(div_print);
                }
            });


        });
    });
</script>
<!-- 打印区域，隐藏 -->
<div style="display: none;" id="div_print">

</div>
<ul class="nav nav-tabs">
    <li class="active"><a href="{php echo $this->createWebUrl('express', array('op'=>'order_list'))}">快递订单</a></li>
    <li ><a href="{php echo $this->createWebUrl('express', array('op'=>'add'))}">添加订单</a></li>
    <li ><a href="{php echo $this->createWebUrl('express', array('op'=>'company'))}">快递公司管理</a></li>
    <li ><a href="{php echo $this->createWebUrl('express', array('op'=>'server'))}">服务社管理</a></li>
</ul>
<div class="main">

    <div class="panel panel-primary">
        <div class="panel-body">
            <div class="row">
                <div class="col-xs-3">收货客户</div>
                <div class="col-xs-2">订单开始时间</div>
                <div class="col-xs-2">订单结束时间</div>
                <div class="col-xs-2">订单状态</div>
                <div class="col-xs-2">收款状态</div>
                <div class="col-xs-3">
                    <input type="text" value="{$key_word}" placeholder="客户名/助记码/电话" id="key_word" class="form-control" onblur="find();" />
                </div>
                <div class="col-xs-2">
                    <input type="date" class="form-control" id="day" value="{$day}" onchange="find();"/>
                </div>
                <div class="col-xs-2">
                    <input type="date" class="form-control" id="end_day" value="{$end_day}" onchange="find();" />
                </div>
                <div class="col-xs-2">
                    <select class="form-control" id="status" onchange="find();">
                        <option value="1" {if $status == 1} selected="selected" {/if}>未完成订单</option>
                        <option value="2" {if $status == 2} selected="selected" {/if} >已完成订单</option>
                        <option value="3" {if $status == 3} selected="selected" {/if} >所有订单</option>
                    </select>
                </div>
                <div class="col-xs-2">
                    <select class="form-control" id="goods_status" onchange="find();">
                        <option value="0">全部状态</option>
                        <option value="1" {if $goods_status == 1} selected="selected" {/if}>已收款</option>
                        <option value="2" {if $goods_status == 2} selected="selected" {/if}>未收款</option>
                    </select>
                </div>

            </div>
            <br />
            <div class="row">

                <div class="col-xs-2">
                    <input type="text" placeholder="快递单号" class="form-control" id="goods_express" value="{$goods_express}" />
                </div>
                <div class="col-xs-2">
                    <select class="form-control" onchange="find();" id="company_id">
                        <option value="0">快递公司</option>
                        {loop $companys $company}
                        <option value="{$company['id']}" {if $company['id'] == $company_id} selected="selected" {/if}>{$company['name']}</option>
                        {/loop}
                    </select>
                </div>
                <!--<div class="col-xs-2">-->
                    <!--<input type="text" onblur="find();" placeholder="收款员" class="form-control" id="cashier" value="{$cashier}" />-->
                <!--</div>-->
                <div class="col-xs-2">
                    <input type="text" onblur="find();" placeholder="货物备注" class="form-control" id="goods_remark" value="{$goods_remark}" />
                </div>
                <div class="col-xs-2">
                    <input type="text" onblur="find();" placeholder="订单备注" class="form-control" id="order_remark" value="{$order_remark}" />
                </div>
                <div class="col-xs-2">
                    <select class="form-control" id="server_id" onchange="find();">
                        <option value="0">服务社</option>
                        {loop $servers $s}
                        <option value="{$s['id']}" {if $s['id'] == $server_id} selected="selected" {/if}>{$s['name']}</option>
                        {/loop}
                    </select>
                </div>
            </div>
            <br />
            <div class="row">
                <div class="col-xs-6">
                    <button type="button" class="btn btn-primary find">搜索</button>
                    <button type="button" class="btn btn-info export-data">导出</button>
                    <!--<button type="button" class="btn btn-warning print">打印</button>-->
                </div>
            </div>
        </div>
    </div>
        <form action="" method="post" class="form-horizontal form" enctype="multipart/form-data">
        <table class="table">
            <tr>
                <td>
                    <input type="checkbox" id="selectAll" />
                </td>
                <td>客户</td>
                <td>电话</td>
                <td>服务社</td>
                <!--<td>快递公司</td>-->
                <td>总件数</td>
                <td>总运费</td>
                <td>已收运费</td>
                <td>总代付款</td>
                <td>已收代付款</td>
                <td>手续费</td>
                <td>已收手续费</td>
                <td>应收</td>
                <td>实收</td>
                <td>日期</td>
                <td>备注</td>
                <td>操作</td>
            </tr>
            {loop $orders $order}
            <tr {if $order['status'] == 2} style="color:green;" {/if}>
                <td>
                    <input type="checkbox" value="{$order['id']}" name="finish_ids[]" />
                </td>
                <td>
                    {$order['member']['name']}
                </td>
                <td>{$order['member']['phone']}</td>
                <td>{$order['server']}</td>
                <!--<td>{$order['company']}</td>-->
                <td>{$order['goods_total']}</td>
                <td>{$order['freight_total']}</td>
                <td>{$order['had_freight_total']}</td>
                <td>{$order['gen_pay_total']}</td>
                <td>{$order['had_gen_pay_total']}</td>
                <td>{$order['charge_total']}</td>
                <td>{$order['had_charge_total']}</td>
                <td>{$order['need_get_total']}</td>
                <td>{$order['had_get_total']}</td>
                <td>{$order['day']}</td>
                <td>{$order['remark']}</td>
                <td>
                    <a href="{php echo $this->createWebUrl('express',array('op' => 'order_goods_add','order_id' => $order['id']))}">
                        <button type="button" class="btn btn-default">编辑</button>
                    </a>
                    {if $order['status'] == 1}
                    <button type="button" class="btn btn-danger del-order" order_id="{$order['id']}">删除</button>
                    {/if}
                </td>
            </tr>
            {/loop}
            <tr>
                <td colspan="3"></td>
                <td>合计：</td>
                <td>{$total_goods_numbers}</td>
                <td>{$all_total_freight}</td>
                <td>{$all_had_freight}</td>
                <td>{$all_gen_pay}</td>
                <td>{$all_had_gen}</td>
                <td>{$all_charge}</td>
                <td>{$all_had_charge}</td>
                <td>{$all_need_get}</td>
                <td>{$all_had_get}</td>
                <td colspan="3"></td>
            </tr>
        </table>
            <div>{$pager}</div>
        <div style="padding:20px;">
            <button type="button" class="btn btn-primary"  data-toggle="modal" data-target="#myModal">完成当日订单</button>
            &nbsp;&nbsp;&nbsp;每页显示
            <select id="page-size">
                <option value="20" {if $psize == 20} selected="selected" {/if}>20</option>
                <option value="100" {if $psize == 100} selected="selected" {/if}>100</option>
                <option value="500" {if $psize == 500} selected="selected" {/if}>500</option>
                <option value="1000" {if $psize == 1000} selected="selected" {/if}>1000</option>
                <option value="5000" {if $psize == 5000} selected="selected" {/if}>5000</option>
                <option value="10000" {if $psize == 10000} selected="selected" {/if}>10000</option>
            </select>
            条
        </div>
    </form>
</div>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">完成顶顶那日期</h4>
            </div>
            <div class="modal-body">
                <input type="date" value="{$finish_day}" id="finish-day" class="form-control" />
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary finish-day-orders">确定</button>
            </div>
        </div>
    </div>
</div>

{template 'common/footer'}